package com.accesshollywood.indexables;

import java.awt.print.PrinterException;
import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.accesshollywood.SQL.GFXSQL;
import com.accesshollywood.SQL.GrfxDateTime;
import com.accesshollywood.grfxOrdering.GRFXOrdersMain;
import com.accesshollywood.grfxOrdering.basics.BLOCK;
import com.accesshollywood.grfxOrdering.basics.STATE;
import com.accesshollywood.grfxOrdering.basics.Users;
import com.accesshollywood.grfxOrdering.panels.ApprovalPanel;
import com.accesshollywood.indexables.items.GrfxItemList;
import com.accesshollywood.indexables.items.TextIndexed;
import com.accesshollywood.p2p.P2P;
import com.accesshollywood.printing.PrintGrfxOrder;

public class GrfxOrder extends Indexed {
	private static boolean	isDeepAccess	= false;						// when true, go all the way down to the SQL database to get or set values

	protected ShowName		showName		= new ShowName();
	protected TextIndexed	summary			= new TextIndexed();
	protected GrfxDateTime	creationDate	= new GrfxDateTime();
	protected GrfxDateTime	dueDate			= new GrfxDateTime();
	protected BLOCK			block			= BLOCK.A;
	protected GraphicType	graphicType		= new GraphicType();
	protected User			orderedBy		= Users.unAssignedOrderer;
	protected User			researcher		= Users.unAssignedResearch;
	protected User			artist			= Users.unAssignedArtist;
	protected User			producer		= Users.unAssignedProducer;
	protected User			photoEdit		= Users.unAssignedPhotoEdit;
	protected User			footage			= Users.unAssignedFootage;
	protected User			legal			= Users.unAssignedLegal;
	protected boolean		apprLegal		= false;
	protected boolean		apprResearch	= false;
	protected boolean		apprPhotoEdit	= false;
	protected boolean		apprFootage		= false;
	protected GrfxItemList	items			= new GrfxItemList();
	protected Destination	destination		= new Destination();
	protected TextIndexed	notes			= new TextIndexed();
	protected boolean		complete		= false;
	protected boolean		closed			= false;
	protected boolean		archived		= false;
	protected boolean		needsLegal		= false;
	protected boolean		needsResearch	= false;
	protected boolean		needsPhotoEdit	= false;
	protected boolean		needsFootage	= false;

	@Override
	public void initSQL() {
		setThat(this);
		tableName = "gfxOrder";
		idColumnName = "idOrder";
		elementColumnName.put(getField("dueDate"), "dueDate");
		elementColumnName.put(getField("creationDate"), "creationDate");
		elementColumnName.put(getField("summary"), "summary");
		elementColumnName.put(getField("items"), "idItemList");
		elementColumnName.put(getField("graphicType"), "idGraphicType");
		elementColumnName.put(getField("showName"), "idShowName");
		elementColumnName.put(getField("block"), "block");
		elementColumnName.put(getField("orderedBy"), "idOrderedBy");
		elementColumnName.put(getField("researcher"), "idResearcher");
		elementColumnName.put(getField("artist"), "idArtist");
		elementColumnName.put(getField("producer"), "idProducer");
		elementColumnName.put(getField("photoEdit"), "idPhotoEdit");
		elementColumnName.put(getField("footage"), "idFootage");
		elementColumnName.put(getField("legal"), "idLegal");
		elementColumnName.put(getField("apprLegal"), "apprLegal");
		elementColumnName.put(getField("apprResearch"), "apprResearch");
		elementColumnName.put(getField("apprPhotoEdit"), "apprPhotoEdit");
		elementColumnName.put(getField("apprFootage"), "apprFootage");
		elementColumnName.put(getField("destination"), "idDestination");
		elementColumnName.put(getField("notes"), "notes");
		elementColumnName.put(getField("complete"), "complete");
		elementColumnName.put(getField("closed"), "closed");
		elementColumnName.put(getField("archived"), "archived");
		elementColumnName.put(getField("needsLegal"), "needsLegal");
		elementColumnName.put(getField("needsResearch"), "needsResearch");
		elementColumnName.put(getField("needsPhotoEdit"), "needsPhotoEdit");
		elementColumnName.put(getField("needsFootage"), "needsFootage");
	}

	public String toString() {
		return "" + getId();// + " : " + summary;
	}

	public String toVerboseString() {
		String output = "";

		output += getId() + "  ";
		output += getGraphicType().name + "  ";
		output += getSummary();
		output += "   due: " + getDueDate().toString() + "\n";

		output += getBlock().str + "   " + getShowName().name + "   destination: " + getDestination().name + "\n";
		output += "ITEMS: \n";
		output += getItems().toString();
		// for (Entry<Integer, GrfxItem> entry : items.entrySet()) {
		// output += ((GrfxItem) entry.getValue()).toString();
		// }
		output += "\nAssigned Artst: " + getArtist().getFullName() + "\n\n";
		if (isNeedsResearch()) {
			output += "Needs Research:\n  Assigned To: " + getResearcher().getFullName() + "\n";
			if (isApprResearch()) {
				output += "   Research APPROVED\n\n";
			} else {
				output += "   Research NOT APPROVED\n\n";
			}
		}
		if (isNeedsPhotoEdit()) {
			output += "Needs Photos:\n  Assigned To: " + getPhotoEdit().getFullName() + "\n";
			if (isApprPhotoEdit()) {
				output += "   Photos ATTACHED\n\n";
			} else {
				output += "   Photos NOT ATTACHED\n\n";
			}
		}
		if (isNeedsFootage()) {
			output += "Needs Footage:\n  Assigned To: " + getFootage().getFullName() + "\n";
			if (isApprFootage()) {
				output += "   Footage SENT\n\n";
			} else {
				output += "   Footage NOT SENT\n\n";
			}
		}
		if (isNeedsLegal()) {
			output += "Needs Legal:\n  Assigned To: " + getLegal().getFullName() + "\n";
			if (isApprLegal()) {
				output += "   Legal APPROVED\n\n";
			} else {
				output += "   Legal NOT APPROVED\n\n";
			}
		}
		output += "\nNOTES: \n" + getNotes() + "\n";
		// Trace.info(output);
		return output;
	}

	public String[] toPrint() {
		String output = "\n\n\n";

		output += "Order # " + getId() + "  ";
		output += getGraphicType().name + "  ";
		output += getSummary();
		output += "   due: " + getDueDate().toString() + "\n";

		output += getBlock().str + "   " + getShowName().name + "\n\n";
		output += "ITEMS: \n";

		output += getItems().toString();

		output += "\nNOTES: \n" + getNotes() + "\n";

		String[] lines = output.split("\\n");

		return lines;
	}

	public ArrayList<User> getUsers() {
		ArrayList<User> toUsers = new ArrayList<User>();
		toUsers.add(getArtist());
		toUsers.add(getResearcher());
		toUsers.add(getPhotoEdit());
		toUsers.add(getFootage());
		toUsers.add(getLegal());
		toUsers.add(getProducer());
		toUsers.add(getOrderedBy());
		return toUsers;
	}

	public ArrayList<User> getAssignedUsers() {
		ArrayList<User> assignedUsers = new ArrayList<User>();
		assignedUsers.add(orderedBy);
		assignedUsers.add(researcher);
		assignedUsers.add(legal);
		return assignedUsers;
	}

	public int calcApprBitMask() {
		int apprBitMask = 0;
		apprBitMask = ((isApprResearch() ? (apprBitMask | ApprovalPanel.flagResearch) : apprBitMask)) |
				((isApprPhotoEdit() ? (apprBitMask | ApprovalPanel.flagPhotoEdit) : apprBitMask)) |
				((isApprFootage() ? (apprBitMask | ApprovalPanel.flagFootage) : apprBitMask)) |
				((isApprLegal() ? (apprBitMask | ApprovalPanel.flagLegal) : apprBitMask));
		return apprBitMask;
	}

	public int calcNeedsBitMask() {
		int needsBitMask = 0;
		needsBitMask = ((isNeedsResearch() ? (needsBitMask | ApprovalPanel.flagResearch) : needsBitMask)) |
				((isNeedsPhotoEdit() ? (needsBitMask | ApprovalPanel.flagPhotoEdit) : needsBitMask)) |
				((isNeedsFootage() ? (needsBitMask | ApprovalPanel.flagFootage) : needsBitMask)) |
				((isNeedsLegal() ? (needsBitMask | ApprovalPanel.flagLegal) : needsBitMask));
		return needsBitMask;
	}

	public STATE getState() {
		if (isArchived()) {
			return STATE.ARCHIVED;
		} else if (isClosed()) {
			return STATE.CLOSED;
		} else if (isComplete()) {
			return STATE.COMPLETED;
		} else if ((!isNeedsResearch() || isApprResearch()) && (!isNeedsPhotoEdit() || isApprPhotoEdit()) && (!isNeedsFootage() || isApprFootage()) && (!isNeedsLegal() || isApprLegal())) {
			return STATE.APPROVED;
		} else {
			return STATE.WAITING_FOR_APPROVAL;
		}
	}

	public void refreshfromSQL() {
		ResultSet rawOrder = GFXSQL.getResultSetFromActiveDB("gfxOrder", "*", this.getId() + "");
	}

	public void refreshfromSQL(String fieldName) {
		Field field;
		try {
			field = this.getClass().getDeclaredField(fieldName);
			getSQLField(field);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		}
		/*
		 * GrfxOrder tempOrder = new GrfxOrder();// GFXSQL.getOrder(this.getId());
		 * tempOrder.fromSQL(this.getId());
		 * Field field;
		 * try {
		 * field = GrfxOrder.class.getDeclaredField(fieldName);
		 * Object value = field.get(tempOrder);
		 * if (fieldName.equals("showName")) {
		 * setShowName((ShowName) value);
		 * } else if (fieldName.equals("summary")) {
		 * setSummary((TextIndexed) value);
		 * } else if (fieldName.equals("dueDate")) {
		 * setDueDate((GrfxDateTime) value);
		 * } else if (fieldName.equals("block")) {
		 * setBlock((BLOCK) value);
		 * } else if (fieldName.equals("graphicType")) {
		 * setGraphicType((GraphicType) value);
		 * } else if (fieldName.equals("orderedBy")) {
		 * setOrderedBy((User) value);
		 * } else if (fieldName.equals("artist")) {
		 * setArtist((User) value);
		 * } else if (fieldName.equals("producer")) {
		 * setProducer((User) value);
		 * } else if (fieldName.equals("researcher")) {
		 * setResearcher((User) value);
		 * } else if (fieldName.equals("photoEdit")) {
		 * setPhotoEdit((User) value);
		 * } else if (fieldName.equals("footage")) {
		 * setFootage((User) value);
		 * } else if (fieldName.equals("legal")) {
		 * setLegal((User) value);
		 * } else if (fieldName.equals("apprResearch")) {
		 * setApprResearch((Boolean) value);
		 * } else if (fieldName.equals("apprPhotoEdit")) {
		 * setApprPhotoEdit((Boolean) value);
		 * } else if (fieldName.equals("apprFootage")) {
		 * setApprFootage((Boolean) value);
		 * } else if (fieldName.equals("apprLegal")) {
		 * setApprLegal((Boolean) value);
		 * } else if (fieldName.equals("items")) {
		 * setItems((GrfxItemList) value);
		 * } else if (fieldName.equals("destination")) {
		 * setDestination((Destination) value);
		 * } else if (fieldName.equals("notes")) {
		 * setNotes((TextIndexed) value);
		 * } else if (fieldName.equals("complete")) {
		 * setComplete((Boolean) value);
		 * } else if (fieldName.equals("closed")) {
		 * setClosed((Boolean) value);
		 * } else if (fieldName.equals("archived")) {
		 * setArchived((Boolean) value);
		 * } else if (fieldName.equals("needsResearch")) {
		 * setNeedsResearch((Boolean) value);
		 * } else if (fieldName.equals("needsPhotoEdit")) {
		 * setNeedsPhotoEdit((Boolean) value);
		 * } else if (fieldName.equals("needsFootage")) {
		 * setNeedsFootage((Boolean) value);
		 * } else if (fieldName.equals("needsLegal")) {
		 * setNeedsLegal((Boolean) value);
		 * }
		 * } catch (Exception e) {
		 * e.printStackTrace();
		 * }
		 */
	}

	public void print() {
		PrintGrfxOrder printer;
		printer = new PrintGrfxOrder();
		String[] header = { summary.toString() };
		String[] body = this.toPrint();
		try {
			boolean didit = printer.doPrint(header, body, true);
		} catch (PrinterException e) {
			e.printStackTrace();
		}
	}

	public static synchronized boolean isDeepAccess() {
		return isDeepAccess;
	}

	public static synchronized void setDeepAccess(boolean isDeepAccess) {
		GrfxOrder.isDeepAccess = isDeepAccess;
	}

	public synchronized ShowName getShowName() {
		return showName;
	}

	public synchronized TextIndexed getSummary() {
		return summary;
	}

	public synchronized GrfxDateTime getCreationDate() {
		return creationDate;
	}

	public synchronized GrfxDateTime getDueDate() {
		return dueDate;
	}

	public synchronized BLOCK getBlock() {
		return block;
	}

	public synchronized GraphicType getGraphicType() {
		return graphicType;
	}

	public synchronized User getOrderedBy() {
		return orderedBy;
	}

	public synchronized User getResearcher() {
		return researcher;
	}

	public synchronized User getArtist() {
		return artist;
	}

	public synchronized User getProducer() {
		return producer;
	}

	public synchronized User getPhotoEdit() {
		return photoEdit;
	}

	public synchronized User getFootage() {
		return footage;
	}

	public synchronized User getLegal() {
		return legal;
	}

	public synchronized boolean isApprLegal() {
		return apprLegal;
	}

	public synchronized boolean isApprResearch() {
		return apprResearch;
	}

	public synchronized boolean isApprPhotoEdit() {
		return apprPhotoEdit;
	}

	public synchronized boolean isApprFootage() {
		return apprFootage;
	}

	public synchronized GrfxItemList getItems() {
		return items;
	}

	public synchronized Destination getDestination() {
		return destination;
	}

	public synchronized TextIndexed getNotes() {
		return notes;
	}

	public synchronized boolean isComplete() {
		return complete;
	}

	public synchronized boolean isClosed() {
		return closed;
	}

	public synchronized boolean isArchived() {
		return archived;
	}

	public synchronized boolean isNeedsLegal() {
		return needsLegal;
	}

	public synchronized boolean isNeedsResearch() {
		return needsResearch;
	}

	public synchronized boolean isNeedsPhotoEdit() {
		return needsPhotoEdit;
	}

	public synchronized boolean isNeedsFootage() {
		return needsFootage;
	}

	private static String getMethodName(final int depth) {
		final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
		return ste[2 + depth].getMethodName();
	}

	private void updateSQLifNecessary() {
		if (isDeepAccess) {
			String firstLetter = getMethodName(1).substring(3, 4).toLowerCase();
			String fieldName = firstLetter + getMethodName(1).substring(4);

			Field field;
			try {
				field = this.getClass().getDeclaredField(fieldName);
				setSQLField(field);
				GRFXOrdersMain.refresh(fieldName, new int[] { this.getId() }, true);
				P2P.refreshPeers(fieldName, new int[] { this.getId() });
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public synchronized void setShowName(ShowName showName) {

		this.showName = showName;
		updateSQLifNecessary();
	}

	public synchronized void setSummary(TextIndexed summary) {

		this.summary = summary;
		updateSQLifNecessary();
	}

	public synchronized void setCreationDate(GrfxDateTime creationDate) {

		this.creationDate = creationDate;
		updateSQLifNecessary();
	}

	public synchronized void setDueDate(GrfxDateTime dueDate) {

		this.dueDate = dueDate;
		updateSQLifNecessary();
	}

	public synchronized void setBlock(BLOCK block) {

		this.block = block;
		updateSQLifNecessary();
	}

	public synchronized void setGraphicType(GraphicType graphicType) {

		this.graphicType = graphicType;
		updateSQLifNecessary();
	}

	public synchronized void setOrderedBy(User orderedBy) {

		this.orderedBy = orderedBy;
		updateSQLifNecessary();
	}

	public synchronized void setResearcher(User researcher) {

		this.researcher = researcher;
		updateSQLifNecessary();
	}

	public synchronized void setArtist(User artist) {

		this.artist = artist;
		updateSQLifNecessary();
	}

	public synchronized void setProducer(User producer) {

		this.producer = producer;
		updateSQLifNecessary();
	}

	public synchronized void setPhotoEdit(User photoEdit) {

		this.photoEdit = photoEdit;
		updateSQLifNecessary();
	}

	public synchronized void setFootage(User footage) {

		this.footage = footage;
		updateSQLifNecessary();
	}

	public synchronized void setLegal(User legal) {

		this.legal = legal;
		updateSQLifNecessary();
	}

	public synchronized void setApprLegal(boolean apprLegal) {

		this.apprLegal = apprLegal;
		updateSQLifNecessary();
	}

	public synchronized void setApprResearch(boolean apprResearch) {

		this.apprResearch = apprResearch;
		updateSQLifNecessary();
	}

	public synchronized void setApprPhotoEdit(boolean apprPhotoEdit) {

		this.apprPhotoEdit = apprPhotoEdit;
		updateSQLifNecessary();
	}

	public synchronized void setApprFootage(boolean apprFootage) {

		this.apprFootage = apprFootage;
		updateSQLifNecessary();
	}

	public synchronized void setItems(GrfxItemList items) {

		this.items = items;
		updateSQLifNecessary();
	}

	public synchronized void setDestination(Destination destination) {

		this.destination = destination;
		updateSQLifNecessary();
	}

	public synchronized void setNotes(TextIndexed notes) {

		this.notes = notes;
		updateSQLifNecessary();
	}

	public synchronized void setComplete(boolean complete) {

		this.complete = complete;
		updateSQLifNecessary();
	}

	public synchronized void setClosed(boolean closed) {

		this.closed = closed;
		updateSQLifNecessary();
	}

	public synchronized void setArchived(boolean archived) {

		this.archived = archived;
		updateSQLifNecessary();
	}

	public synchronized void setNeedsLegal(boolean needsLegal) {

		this.needsLegal = needsLegal;
		updateSQLifNecessary();
	}

	public synchronized void setNeedsResearch(boolean needsResearch) {

		this.needsResearch = needsResearch;
		updateSQLifNecessary();
	}

	public synchronized void setNeedsPhotoEdit(boolean needsPhotoEdit) {

		this.needsPhotoEdit = needsPhotoEdit;
		updateSQLifNecessary();
	}

	public synchronized void setNeedsFootage(boolean needsFootage) {

		this.needsFootage = needsFootage;
		updateSQLifNecessary();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + (apprFootage ? 1231 : 1237);
		result = prime * result + (apprLegal ? 1231 : 1237);
		result = prime * result + (apprPhotoEdit ? 1231 : 1237);
		result = prime * result + (apprResearch ? 1231 : 1237);
		result = prime * result + (archived ? 1231 : 1237);
		result = prime * result + ((artist == null) ? 0 : artist.hashCode());
		result = prime * result + ((block == null) ? 0 : block.hashCode());
		result = prime * result + (closed ? 1231 : 1237);
		result = prime * result + (complete ? 1231 : 1237);
		result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode());
		result = prime * result + ((destination == null) ? 0 : destination.hashCode());
		result = prime * result + ((dueDate == null) ? 0 : dueDate.hashCode());
		result = prime * result + ((footage == null) ? 0 : footage.hashCode());
		result = prime * result + ((graphicType == null) ? 0 : graphicType.hashCode());
		result = prime * result + ((items == null) ? 0 : items.hashCode());
		result = prime * result + ((legal == null) ? 0 : legal.hashCode());
		result = prime * result + (needsFootage ? 1231 : 1237);
		result = prime * result + (needsLegal ? 1231 : 1237);
		result = prime * result + (needsPhotoEdit ? 1231 : 1237);
		result = prime * result + (needsResearch ? 1231 : 1237);
		result = prime * result + ((notes == null) ? 0 : notes.hashCode());
		result = prime * result + ((orderedBy == null) ? 0 : orderedBy.hashCode());
		result = prime * result + ((photoEdit == null) ? 0 : photoEdit.hashCode());
		result = prime * result + ((producer == null) ? 0 : producer.hashCode());
		result = prime * result + ((researcher == null) ? 0 : researcher.hashCode());
		result = prime * result + ((showName == null) ? 0 : showName.hashCode());
		result = prime * result + ((summary == null) ? 0 : summary.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		GrfxOrder other = (GrfxOrder) obj;
		if (apprFootage != other.apprFootage)
			return false;
		if (apprLegal != other.apprLegal)
			return false;
		if (apprPhotoEdit != other.apprPhotoEdit)
			return false;
		if (apprResearch != other.apprResearch)
			return false;
		if (archived != other.archived)
			return false;
		if (artist == null) {
			if (other.artist != null)
				return false;
		} else if (!artist.equals(other.artist))
			return false;
		if (block != other.block)
			return false;
		if (closed != other.closed)
			return false;
		if (complete != other.complete)
			return false;
		if (creationDate == null) {
			if (other.creationDate != null)
				return false;
		} else if (!creationDate.equals(other.creationDate))
			return false;
		if (destination == null) {
			if (other.destination != null)
				return false;
		} else if (!destination.equals(other.destination))
			return false;
		if (dueDate == null) {
			if (other.dueDate != null)
				return false;
		} else if (!dueDate.equals(other.dueDate))
			return false;
		if (footage == null) {
			if (other.footage != null)
				return false;
		} else if (!footage.equals(other.footage))
			return false;
		if (graphicType == null) {
			if (other.graphicType != null)
				return false;
		} else if (!graphicType.equals(other.graphicType))
			return false;
		if (items == null) {
			if (other.items != null)
				return false;
		} else if (!items.equals(other.items))
			return false;
		if (legal == null) {
			if (other.legal != null)
				return false;
		} else if (!legal.equals(other.legal))
			return false;
		if (needsFootage != other.needsFootage)
			return false;
		if (needsLegal != other.needsLegal)
			return false;
		if (needsPhotoEdit != other.needsPhotoEdit)
			return false;
		if (needsResearch != other.needsResearch)
			return false;
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (orderedBy == null) {
			if (other.orderedBy != null)
				return false;
		} else if (!orderedBy.equals(other.orderedBy))
			return false;
		if (photoEdit == null) {
			if (other.photoEdit != null)
				return false;
		} else if (!photoEdit.equals(other.photoEdit))
			return false;
		if (producer == null) {
			if (other.producer != null)
				return false;
		} else if (!producer.equals(other.producer))
			return false;
		if (researcher == null) {
			if (other.researcher != null)
				return false;
		} else if (!researcher.equals(other.researcher))
			return false;
		if (showName == null) {
			if (other.showName != null)
				return false;
		} else if (!showName.equals(other.showName))
			return false;
		if (summary == null) {
			if (other.summary != null)
				return false;
		} else if (!summary.equals(other.summary))
			return false;
		return true;
	}

	/*
	 * extends DefaultMutableTreeNode implements Cloneable {
	 * protected int idOrder = -1;
	 * protected ShowName showName = new ShowName();
	 * protected IndexedSQL<String> summary = new IndexedSQL<String>();
	 * protected SQLDate creationDate = new SQLDate();
	 * protected SQLDate dueDate = new SQLDate();
	 * protected BLOCK block = BLOCK.A;
	 * protected GraphicType graphicType = new GraphicType();
	 * protected User orderedBy = Users.unAssignedOrderer;
	 * protected User researcher = Users.unAssignedResearch;
	 * protected User artist = Users.unAssignedArtist;
	 * protected User producer = Users.unAssignedProducer;
	 * protected User photoEdit = Users.unAssignedPhotoEdit;
	 * protected User footage = Users.unAssignedFootage;
	 * protected User legal = Users.unAssignedLegal;
	 * protected boolean apprLegal = false;
	 * protected boolean apprResearch = false;
	 * protected boolean apprPhotoEdit = false;
	 * protected boolean apprFootage = false;
	 * protected IndexedSQL<GrfxItemList> items = new IndexedSQL<GrfxItemList>();
	 * protected Destination destination = new Destination();
	 * protected IndexedSQL<String> notes = new IndexedSQL<String>();
	 * protected boolean complete = false;
	 * protected boolean closed = false;
	 * protected boolean archived = false;
	 * protected boolean needsLegal = false;
	 * protected boolean needsResearch = false;
	 * protected boolean needsPhotoEdit = false;
	 * protected boolean needsFootage = false;
	 * protected PropertyChangeSupport mPcs = new PropertyChangeSupport(this);
	 * public GrfxOrder() {
	 * super(null);
	 * }
	 * public GrfxOrder(boolean justShowItemNodes) {
	 * super(null);
	 * if (justShowItemNodes) {
	 * ItemTreeNode branch = new ItemTreeNode(this);
	 * add(branch);
	 * }
	 * }
	 * public GrfxOrder clone() {
	 * GrfxOrder newOrder = new GrfxOrder();
	 * Field[] fields = GrfxOrder.class.getDeclaredFields();
	 * try {
	 * for (Field currField : fields) {
	 * Field oldField = this.getClass().getDeclaredField(currField.getName());
	 * Field newField = newOrder.getClass().getDeclaredField(currField.getName());
	 * newField.set(newOrder, oldField.get(this));
	 * }
	 * } catch (Exception e) {
	 * e.printStackTrace();
	 * }
	 * return newOrder;
	 * }
	 * public ArrayList<User> getUsers() {
	 * ArrayList<User> toUsers = new ArrayList<User>();
	 * toUsers.add(this.getArtist());
	 * toUsers.add(this.getResearcher());
	 * toUsers.add(this.getPhotoEdit());
	 * toUsers.add(this.getFootage());
	 * toUsers.add(this.getLegal());
	 * toUsers.add(this.getProducer());
	 * toUsers.add(this.getOrderedBy());
	 * return toUsers;
	 * }
	 * public STATE getState() {
	 * if (archived) {
	 * return STATE.ARCHIVED;
	 * } else if (closed) {
	 * return STATE.CLOSED;
	 * } else if (complete) {
	 * return STATE.COMPLETED;
	 * } else if ((!needsResearch || apprResearch) && (!needsPhotoEdit || apprPhotoEdit) && (!needsFootage || apprFootage) && (!needsLegal || apprLegal)) {
	 * return STATE.APPROVED;
	 * } else {
	 * return STATE.WAITING_FOR_APPROVAL;
	 * }
	 * }
	 * public GrfxOrder(ResultSet rawOrder) {
	 * super(null);
	 * if (Users.allUsers == null) {
	 * Users.populateUsers();
	 * }
	 * fromResultSet(rawOrder);
	 * addSubTree();
	 * }
	 * public IndexedSQL<GrfxItemList> getItems(ResultSet rawOrder) throws SQLException {
	 * int idItemList = rawOrder.getInt("idItemList");
	 * // LinkedHashMap<Integer, GrfxItem> currItems = GFXSQL.getItems(idItemList);
	 * IndexedSQL<GrfxItemList> currItems = GFXSQL.getItems(idItemList);
	 * return currItems;
	 * }
	 * public String toString() {
	 * return "" + idOrder;// + " : " + summary;
	 * }
	 * public String toVerboseString() {
	 * String output = "";
	 * output += idOrder + "  ";
	 * output += graphicType.name + "  ";
	 * output += summary;
	 * output += "   due: " + dueDate.toString() + "\n";
	 * output += block.str + "   " + showName.name + "   destination: " + destination.name + "\n";
	 * output += "ITEMS: \n";
	 * output += items.toString();
	 * // for (Entry<Integer, GrfxItem> entry : items.entrySet()) {
	 * // output += ((GrfxItem) entry.getValue()).toString();
	 * // }
	 * output += "\nAssigned Artst: " + artist.getFullName() + "\n\n";
	 * if (needsResearch) {
	 * output += "Needs Research:\n  Assigned To: " + researcher.getFullName() + "\n";
	 * if (apprResearch) {
	 * output += "   Research APPROVED\n\n";
	 * } else {
	 * output += "   Research NOT APPROVED\n\n";
	 * }
	 * }
	 * if (needsPhotoEdit) {
	 * output += "Needs Photos:\n  Assigned To: " + photoEdit.getFullName() + "\n";
	 * if (apprPhotoEdit) {
	 * output += "   Photos ATTACHED\n\n";
	 * } else {
	 * output += "   Photos NOT ATTACHED\n\n";
	 * }
	 * }
	 * if (needsFootage) {
	 * output += "Needs Footage:\n  Assigned To: " + footage.getFullName() + "\n";
	 * if (apprFootage) {
	 * output += "   Footage SENT\n\n";
	 * } else {
	 * output += "   Footage NOT SENT\n\n";
	 * }
	 * }
	 * if (needsLegal) {
	 * output += "Needs Legal:\n  Assigned To: " + legal.getFullName() + "\n";
	 * if (apprLegal) {
	 * output += "   Legal APPROVED\n\n";
	 * } else {
	 * output += "   Legal NOT APPROVED\n\n";
	 * }
	 * }
	 * output += "\nNOTES: \n" + notes + "\n";
	 * // Trace.info(output);
	 * return output;
	 * }
	 * public String[] toPrint() {
	 * String output = "\n\n\n";
	 * output += "Order # " + idOrder + "  ";
	 * output += graphicType.name + "  ";
	 * output += summary;
	 * output += "   due: " + dueDate.toString() + "\n";
	 * output += block.str + "   " + showName.name + "\n\n";
	 * output += "ITEMS: \n";
	 * output += items.toString();
	 * /*
	 * output += "\nAssigned Artst: " + artist.getFullName() + "\n\n";
	 * if (needsResearch) {
	 * output += "Needs Research:\n  Assigned To: " + researcher.getFullName() + "\n";
	 * if (apprResearch) {
	 * output += "   Research APPROVED\n\n";
	 * } else {
	 * output += "   Research NOT APPROVED\n\n";
	 * }
	 * }
	 * if (needsPhotoEdit) {
	 * output += "Needs Photos:\n  Assigned To: " + photoEdit.getFullName() + "\n";
	 * if (apprPhotoEdit) {
	 * output += "   Photos ATTACHED\n\n";
	 * } else {
	 * output += "   Photos NOT ATTACHED\n\n";
	 * }
	 * }
	 * if (needsFootage) {
	 * output += "Needs Footage:\n  Assigned To: " + footage.getFullName() + "\n";
	 * if (apprFootage) {
	 * output += "   Footage SENT\n\n";
	 * } else {
	 * output += "   Footage NOT SENT\n\n";
	 * }
	 * }
	 * if (needsLegal) {
	 * output += "Needs Legal:\n  Assigned To: " + legal.getFullName() + "\n";
	 * if (apprLegal) {
	 * output += "   Legal APPROVED\n\n";
	 * } else {
	 * output += "   Legal NOT APPROVED\n\n";
	 * }
	 * }
	 * //
	 * output += "\nNOTES: \n" + notes + "\n";
	 * String[] lines = output.split("\\n");
	 * return lines;
	 * }
	 * public ArrayList<User> getAssignedUsers() {
	 * ArrayList<User> assignedUsers = new ArrayList<User>();
	 * assignedUsers.add(orderedBy);
	 * assignedUsers.add(researcher);
	 * assignedUsers.add(legal);
	 * return assignedUsers;
	 * }
	 * protected void addSubTree() {
	 * addApprBranch();
	 * addItems();
	 * // addText();
	 * // addStills();
	 * // addFootage();
	 * addSpecifics();
	 * addNotes();
	 * }
	 * protected void addApprBranch() {
	 * ApprTreeNode branch = new ApprTreeNode(this);
	 * add(branch);
	 * }
	 * protected void addSpecifics() {
	 * SpecificsTreeNode branch = new SpecificsTreeNode(this);
	 * add(branch);
	 * }
	 * protected void addText() {
	 * TextTreeNode branch = new TextTreeNode(this);
	 * add(branch);
	 * }
	 * protected void addStills() {
	 * StillGroupTreeNode branch = new StillGroupTreeNode(this);
	 * add(branch);
	 * }
	 * protected void addFootage() {
	 * FootageGroupTreeNode branch = new FootageGroupTreeNode(this);
	 * add(branch);
	 * }
	 * protected void addNotes() {
	 * NotesTreeNode branch = new NotesTreeNode(this);
	 * add(branch);
	 * }
	 * protected void addItems() {
	 * if (!items.isEmpty()) {
	 * ItemTreeNode branch = new ItemTreeNode(this);
	 * add(branch);
	 * }
	 * }
	 * public int calcApprBitMask() {
	 * int apprBitMask = 0;
	 * apprBitMask = ((apprResearch ? (apprBitMask | ApprPanel.flagResearch) : apprBitMask)) |
	 * ((apprPhotoEdit ? (apprBitMask | ApprPanel.flagPhotoEdit) : apprBitMask)) |
	 * ((apprFootage ? (apprBitMask | ApprPanel.flagFootage) : apprBitMask)) |
	 * ((apprLegal ? (apprBitMask | ApprPanel.flagLegal) : apprBitMask));
	 * return apprBitMask;
	 * }
	 * public int calcNeedsBitMask() {
	 * int needsBitMask = 0;
	 * needsBitMask = ((needsResearch ? (needsBitMask | ApprPanel.flagResearch) : needsBitMask)) |
	 * ((needsPhotoEdit ? (needsBitMask | ApprPanel.flagPhotoEdit) : needsBitMask)) |
	 * ((needsFootage ? (needsBitMask | ApprPanel.flagFootage) : needsBitMask)) |
	 * ((needsLegal ? (needsBitMask | ApprPanel.flagLegal) : needsBitMask));
	 * return needsBitMask;
	 * }
	 * public void print() {
	 * PrintGrfxOrder printer;
	 * printer = new PrintGrfxOrder();
	 * String[] header = { summary.toString() };
	 * String[] body = this.toPrint();
	 * try {
	 * boolean didit = printer.doPrint(header, body, true);
	 * } catch (PrinterException e) {
	 * e.printStackTrace();
	 * }
	 * }
	 * //
	 * // GETTERS
	 * //
	 * public int getIdOrder() {
	 * return idOrder;
	 * }
	 * public ShowName getShowName() {
	 * return showName;
	 * }
	 * public IndexedSQL<String> getSummary() {
	 * return summary;
	 * }
	 * public SQLDate getCreationDate() {
	 * return creationDate;
	 * }
	 * public SQLDate getDueDate() {
	 * return dueDate;
	 * }
	 * public BLOCK getBlock() {
	 * return block;
	 * }
	 * public GraphicType getGraphicType() {
	 * return graphicType;
	 * }
	 * public User getOrderedBy() {
	 * return orderedBy;
	 * }
	 * public IndexedSQL<String> getNotes() {
	 * return notes;
	 * }
	 * public String getNotesSQL() {
	 * return notes.toString();
	 * }
	 * public boolean isComplete() {
	 * return complete;
	 * }
	 * public boolean isClosed() {
	 * return closed;
	 * }
	 * public boolean isArchived() {
	 * return archived;
	 * }
	 * public boolean needsLegal() {
	 * return needsLegal;
	 * }
	 * public boolean needsResearch() {
	 * return needsResearch;
	 * }
	 * public boolean needsPhotoEdit() {
	 * return needsPhotoEdit;
	 * }
	 * public boolean needsFootage() {
	 * return needsFootage;
	 * }
	 * public boolean isApprPhotoEdit() {
	 * return apprPhotoEdit;
	 * }
	 * public User getResearcher() {
	 * return researcher;
	 * }
	 * public User getArtist() {
	 * return artist;
	 * }
	 * public User getProducer() {
	 * return producer;
	 * }
	 * public User getPhotoEdit() {
	 * return photoEdit;
	 * }
	 * public User getLegal() {
	 * return legal;
	 * }
	 * public User getFootage() {
	 * return footage;
	 * }
	 * public boolean isApprLegal() {
	 * return apprLegal;
	 * }
	 * public boolean isApprResearch() {
	 * return apprResearch;
	 * }
	 * public boolean isApprFootage() {
	 * return apprFootage;
	 * }
	 * public IndexedSQL<GrfxItemList> getItems() {
	 * return items;
	 * }
	 * public Destination getDestination() {
	 * return destination;
	 * }
	 * //
	 * // VERBOSE SET MODES update SQL, send email alerts, and whatever else needs to be done
	 * //
	 * public void setIdOrder(int idOrder) {
	 * mPcs.firePropertyChange("idOrder", this.idOrder, idOrder);
	 * this.idOrder = idOrder;
	 * GRFXOrdersMain.refresh(new int[] { this.getIdOrder() });
	 * P2P.refreshPeers("idOrder", new int[] { idOrder });
	 * }
	 * public void setShowName(ShowName showName) {
	 * GrfxOrder oldOrder = this.clone();
	 * this.showName = showName;
	 * Notify.orderModified(oldOrder, this, Users.currentUser);
	 * GFXSQL.alterInt("gfxOrder", "idShowName", showName.idShowName, this.getIdOrder());
	 * GRFXOrdersMain.refresh("showName", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "showName" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("idShowName", new int[] { idOrder });
	 * }
	 * public void setSummary(IndexedSQL<String> summary) {
	 * mPcs.firePropertyChange("summary", this.summary, summary);
	 * this.summary = summary;
	 * GRFXOrdersMain.refresh("summary", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "summary" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("summary", new int[] { idOrder });
	 * }
	 * public void setCreationDate(SQLDate creationDate) {
	 * mPcs.firePropertyChange("creationDate", this.creationDate, creationDate);
	 * this.creationDate = creationDate;
	 * GRFXOrdersMain.refresh(new int[] { this.getIdOrder() });
	 * P2P.refreshPeers("creationDate", new int[] { idOrder });
	 * }
	 * public void setDueDate(SQLDate dueDate) {
	 * mPcs.firePropertyChange("dueDate", this.dueDate, dueDate);
	 * Notify.deadlineChanged(this, Users.currentUser, this.dueDate.toString(), dueDate.toString());
	 * GFXSQL.alterString("gfxOrder", "dueDate", dueDate.toSQL(), this.getIdOrder());
	 * this.dueDate = dueDate;
	 * // GRFXOrdersMain.refresh("dueDate", new int[] { this.getIdOrder() }, true);
	 * GRFXOrdersMain.refresh(true);
	 * P2P.refreshPeers("dueDate", new int[] { idOrder });
	 * }
	 * public void setBlock(BLOCK block) {
	 * mPcs.firePropertyChange("block", this.block, block);
	 * GrfxOrder oldOrder = this.clone();
	 * this.block = block;
	 * Notify.orderModified(oldOrder, this, Users.currentUser);
	 * GFXSQL.alterString("gfxOrder", "block", block.name(), this.getIdOrder());
	 * // GRFXOrdersMain.refresh("block", new int[] { this.getIdOrder() }, true);
	 * GRFXOrdersMain.refresh(true);
	 * P2P.refreshPeers("block", new int[] { idOrder });
	 * }
	 * public void setGraphicType(GraphicType graphicType) {
	 * mPcs.firePropertyChange("graphicType", this.graphicType, graphicType);
	 * GrfxOrder oldOrder = this.clone();
	 * this.graphicType = graphicType;
	 * Notify.orderModified(oldOrder, this, Users.currentUser);
	 * GFXSQL.alterInt("gfxOrder", "idGraphicType", graphicType.idGraphicType, this.getIdOrder());
	 * GRFXOrdersMain.refresh("graphicType", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "graphicType" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("idGraphicType", new int[] { idOrder });
	 * }
	 * public void setDestination(Destination destination) {
	 * mPcs.firePropertyChange("destination", this.destination, destination);
	 * GrfxOrder oldOrder = this.clone();
	 * this.destination = destination;
	 * Notify.orderModified(oldOrder, this, Users.currentUser);
	 * GFXSQL.alterInt("gfxOrder", "idDestination", destination.idDestination, this.getIdOrder());
	 * GRFXOrdersMain.refresh("destination", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "destination" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("destination", new int[] { idOrder });
	 * }
	 * public void setOrderedBy(User newUser) {
	 * mPcs.firePropertyChange("orderedBy", this.orderedBy, orderedBy);
	 * this.orderedBy = orderedBy;
	 * try {
	 * GFXSQL.setUser(newUser, "idOrderedBy", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("orderedBy", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "orderedBy" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("orderedBy", new int[] { idOrder });
	 * }
	 * public void setResearch(User newUser) {
	 * mPcs.firePropertyChange("researcher", this.researcher, researcher);
	 * this.researcher = researcher;
	 * try {
	 * GFXSQL.setUser(newUser, "idResearcher", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("researcher", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "researcher" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("researcher", new int[] { idOrder });
	 * }
	 * public void setArtist(User newUser) {
	 * mPcs.firePropertyChange("artist", this.artist, artist);
	 * this.artist = artist;
	 * try {
	 * GFXSQL.setUser(newUser, "idArtist", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("artist", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "artist" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("artist", new int[] { idOrder });
	 * }
	 * public void setProducer(User newUser) {
	 * mPcs.firePropertyChange("producer", this.producer, producer);
	 * this.producer = producer;
	 * try {
	 * GFXSQL.setUser(newUser, "idProducer", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("producer", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "producer" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("producer", new int[] { idOrder });
	 * }
	 * public void setPhotoEdit(User newUser) {
	 * mPcs.firePropertyChange("photoEdit", this.photoEdit, photoEdit);
	 * this.photoEdit = photoEdit;
	 * try {
	 * GFXSQL.setUser(newUser, "idPhotoEdit", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("photoEdit", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "photoEdit" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("photoEdit", new int[] { idOrder });
	 * }
	 * public void setFootage(User newUser) {
	 * mPcs.firePropertyChange("footage", this.footage, footage);
	 * this.footage = footage;
	 * try {
	 * GFXSQL.setUser(newUser, "idFootage", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("footage", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "footage" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("footage", new int[] { idOrder });
	 * }
	 * public void setLegal(User newUser) {
	 * mPcs.firePropertyChange("legal", this.legal, legal);
	 * this.legal = legal;
	 * try {
	 * GFXSQL.setUser(newUser, "idLegal", this.getIdOrder());
	 * } catch (SQLException e) {
	 * e.printStackTrace();
	 * }
	 * GRFXOrdersMain.refresh("legal", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "legal" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("legal", new int[] { idOrder });
	 * }
	 * public void setApprPhotoEdit(boolean apprPhotoEdit) {
	 * mPcs.firePropertyChange("apprPhotoEdit", this.apprPhotoEdit, apprPhotoEdit);
	 * Notify.photoEditApproved(this);
	 * this.apprPhotoEdit = apprPhotoEdit;
	 * GRFXOrdersMain.refresh("apprPhotoEdit", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "apprPhotoEdit" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("apprPhotoEdit", new int[] { idOrder });
	 * }
	 * public void setApprLegal(boolean apprLegal) {
	 * mPcs.firePropertyChange("apprLegal", this.apprLegal, apprLegal);
	 * Notify.legalApproved(this);
	 * this.apprLegal = apprLegal;
	 * GRFXOrdersMain.refresh("apprLegal", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "apprLegal" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("apprLegal", new int[] { idOrder });
	 * }
	 * public void setApprResearch(boolean apprResearch) {
	 * mPcs.firePropertyChange("apprResearch", this.apprResearch, apprResearch);
	 * Notify.researchApproved(this);
	 * this.apprResearch = apprResearch;
	 * GRFXOrdersMain.refresh("apprResearch", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "apprResearch" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("apprResearch", new int[] { idOrder });
	 * }
	 * public void setApprFootage(boolean apprFootage) {
	 * mPcs.firePropertyChange("apprFootage", this.apprFootage, apprFootage);
	 * Notify.footageApproved(this);
	 * this.apprFootage = apprFootage;
	 * GRFXOrdersMain.refresh("apprFootage", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "apprFootage" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("apprFootage", new int[] { idOrder });
	 * }
	 * public void setItems(IndexedSQL<GrfxItemList> items) {
	 * mPcs.firePropertyChange("items", this.items, items);
	 * this.items = items;
	 * GRFXOrdersMain.refresh("items", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "items" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("items", new int[] { idOrder });
	 * }
	 * public void setNotes(IndexedSQL<String> notes) {
	 * mPcs.firePropertyChange("notes", this.notes, notes);
	 * this.notes = notes;
	 * GRFXOrdersMain.refresh("notes", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "notes" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("notes", new int[] { idOrder });
	 * }
	 * public void setComplete(boolean complete) {
	 * mPcs.firePropertyChange("complete", this.complete, complete);
	 * GFXSQL.alterBoolean("gfxOrder", "complete", complete, this.getIdOrder());
	 * Notify.markedComplete(this);
	 * this.complete = complete;
	 * GRFXOrdersMain.refresh("complete", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "complete" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("complete", new int[] { idOrder });
	 * }
	 * public void setClosed(boolean closed) {
	 * mPcs.firePropertyChange("closed", this.closed, closed);
	 * if (closed) {
	 * Notify.orderClosed(this);
	 * } else {
	 * Notify.orderReopened(this, Users.currentUser);
	 * }
	 * this.closed = closed;
	 * boolean itWorked = GFXSQL.closeOrder(getIdOrder(), closed);
	 * GRFXOrdersMain.refresh("closed", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "closed" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("closed", new int[] { idOrder });
	 * }
	 * public void setArchived(boolean archived) {
	 * mPcs.firePropertyChange("archived", this.archived, archived);
	 * if (archived) {
	 * Notify.orderArchived(this);
	 * } else {
	 * Notify.orderUnArchived(this, Users.currentUser);
	 * }
	 * this.archived = archived;
	 * GFXSQL.archiveOrder(getIdOrder(), archived);
	 * GRFXOrdersMain.refresh("archived", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "archived" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("archived", new int[] { idOrder });
	 * }
	 * public void setNeedsLegal(boolean needsLegal) {
	 * mPcs.firePropertyChange("needsLegal", this.needsLegal, needsLegal);
	 * this.needsLegal = needsLegal;
	 * GRFXOrdersMain.refresh("needsLegal", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "needsLegal" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("needsLegal", new int[] { idOrder });
	 * }
	 * public void setNeedsResearch(boolean needsResearch) {
	 * mPcs.firePropertyChange("needsResearch", this.needsResearch, needsResearch);
	 * this.needsResearch = needsResearch;
	 * GRFXOrdersMain.refresh("needsResearch", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "needsResearch" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("needsResearch", new int[] { idOrder });
	 * }
	 * public void setNeedsPhotoEdit(boolean needsPhotoEdit) {
	 * mPcs.firePropertyChange("needsPhotoEdit", this.needsPhotoEdit, needsPhotoEdit);
	 * this.needsPhotoEdit = needsPhotoEdit;
	 * GRFXOrdersMain.refresh("needsPhotoEdit", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "needsPhotoEdit" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("needsPhotoEdit", new int[] { idOrder });
	 * }
	 * public void setNeedsFootage(boolean needsFootage) {
	 * mPcs.firePropertyChange("needsFootage", this.needsFootage, needsFootage);
	 * this.needsFootage = needsFootage;
	 * GRFXOrdersMain.refresh("needsFootage", new int[] { this.getIdOrder() }, true);
	 * // GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "needsFootage" + "~~~" + this.getIdOrder());
	 * P2P.refreshPeers("needsFootage", new int[] { idOrder });
	 * }
	 * //
	 * // QUIET SET MODES do not update SQL (since SQL is probably being used to update the order...)
	 * //
	 * public void setIdOrderQuiet(int idOrder) {
	 * this.idOrder = idOrder;
	 * }
	 * public void setShowNameQuiet(ShowName showName) {
	 * this.showName = showName;
	 * // GRFXOrdersMain.refresh("showName", new int[] { this.getIdOrder() }, false);
	 * // //GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "showName" + "~~~" + this.getIdOrder());
	 * }
	 * public void setSummaryQuiet(IndexedSQL<String> summary) {
	 * this.summary = summary;
	 * // GRFXOrdersMain.refresh("summary", new int[] { this.getIdOrder() }, false);
	 * // //GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "summary" + "~~~" + this.getIdOrder());
	 * }
	 * public void setCreationDateQuiet(SQLDate creationDate) {
	 * this.creationDate = creationDate;
	 * }
	 * public void setDueDateQuiet(SQLDate dueDate) {
	 * this.dueDate = dueDate;
	 * // GRFXOrdersMain.refresh("dueDate", new int[] { this.getIdOrder() }, false);
	 * // //GRFXOrdersMain.serverSocket.sendToClients(GfxProtocol.COMMAND.REFRESH, "dueDate" + "~~~" + this.getIdOrder());
	 * }
	 * public void setBlockQuiet(BLOCK block) {
	 * this.block = block;
	 * // GRFXOrdersMain.refreshSolo("block", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setGraphicTypeQuiet(GraphicType graphicType) {
	 * this.graphicType = graphicType;
	 * // GRFXOrdersMain.refreshSolo("graphicType", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setOrderedByQuiet(User orderedBy) {
	 * this.orderedBy = orderedBy;
	 * // GRFXOrdersMain.refreshSolo("orderedBy", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setResearcherQuiet(User researcher) {
	 * this.researcher = researcher;
	 * // GRFXOrdersMain.refreshSolo("research", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setArtistQuiet(User artist) {
	 * this.artist = artist;
	 * // GRFXOrdersMain.refreshSolo("artist", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setProducerQuiet(User producer) {
	 * this.producer = producer;
	 * // GRFXOrdersMain.refreshSolo("producer", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setPhotoEditQuiet(User photoEdit) {
	 * this.photoEdit = photoEdit;
	 * // GRFXOrdersMain.refreshSolo("photoEdit", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setFootageQuiet(User footage) {
	 * this.footage = footage;
	 * // GRFXOrdersMain.refreshSolo("footage", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setLegalQuiet(User legal) {
	 * this.legal = legal;
	 * // GRFXOrdersMain.refreshSolo("legal", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setApprLegalQuiet(boolean apprLegal) {
	 * this.apprLegal = apprLegal;
	 * // GRFXOrdersMain.refreshSolo("apprLegal", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setApprResearchQuiet(boolean apprResearch) {
	 * this.apprResearch = apprResearch;
	 * // GRFXOrdersMain.refreshSolo("apprResearch", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setApprFootageQuiet(boolean apprFootage) {
	 * this.apprFootage = apprFootage;
	 * // GRFXOrdersMain.refreshSolo("apprFootage", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setApprPhotoEditQuiet(boolean newValue) {
	 * apprPhotoEdit = true;
	 * // GRFXOrdersMain.refreshSolo("apprPhotoEdit", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setItemsQuiet(IndexedSQL<GrfxItemList> items) {
	 * this.items = items;
	 * // GRFXOrdersMain.refreshSolo("items", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setDestinationQuiet(Destination destination) {
	 * this.destination = destination;
	 * // GRFXOrdersMain.refreshSolo("destination", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setNotesQuiet(IndexedSQL<String> notes) {
	 * this.notes = notes;
	 * // GRFXOrdersMain.refreshSolo("notes", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setCompleteQuiet(boolean complete) {
	 * this.complete = complete;
	 * // GRFXOrdersMain.refreshSolo("complete", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setClosedQuiet(boolean closed) {
	 * this.closed = closed;
	 * // GRFXOrdersMain.refreshSolo("closed", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setArchivedQuiet(boolean archived) {
	 * this.archived = archived;
	 * // GRFXOrdersMain.refreshSolo("archived", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setNeedsLegalQuiet(boolean needsLegal) {
	 * this.needsLegal = needsLegal;
	 * // GRFXOrdersMain.refreshSolo("needsLegal", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setNeedsResearchQuiet(boolean needsResearch) {
	 * this.needsResearch = needsResearch;
	 * // GRFXOrdersMain.refreshSolo("needsResearch", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setNeedsPhotoEditQuiet(boolean needsPhotoEdit) {
	 * this.needsPhotoEdit = needsPhotoEdit;
	 * // GRFXOrdersMain.refreshSolo("needsPhotoEdit", new int[] { this.getIdOrder() }, false);
	 * }
	 * public void setNeedsFootageQuiet(boolean needsFootage) {
	 * this.needsFootage = needsFootage;
	 * // GRFXOrdersMain.refreshSolo("needsFootage", new int[] { this.getIdOrder() }, false);
	 * }
	 * //
	 * public void fromResultSet(ResultSet rawOrder) {
	 * try {
	 * idOrder = rawOrder.getInt("idOrder");
	 * summary = new IndexedSQL<String>(idOrder, rawOrder.getString("summary"));
	 * block = BLOCK.fromString(rawOrder.getString("block"));
	 * creationDate = new SQLDate(rawOrder.getLong("creationDate"));
	 * dueDate = new SQLDate(rawOrder.getLong("dueDate"));
	 * graphicType = GFXSQL.getGraphicType(rawOrder.getInt("idGraphicType"));
	 * showName = ShowNames.allShowNames.get(rawOrder.getInt("idShowName"));
	 * // Trace.info("graphicType = " + graphicType);
	 * orderedBy = GFXSQL.getUser(rawOrder.getInt("idOrderedBy"));
	 * artist = GFXSQL.getUser(rawOrder.getInt("idArtist"));//
	 * researcher = GFXSQL.getUser(rawOrder.getInt("idResearcher"));
	 * photoEdit = GFXSQL.getUser(rawOrder.getInt("idPhotoEdit"));
	 * footage = GFXSQL.getUser(rawOrder.getInt("idFootage"));
	 * legal = GFXSQL.getUser(rawOrder.getInt("idLegal"));
	 * producer = GFXSQL.getUser(rawOrder.getInt("idProducer"));
	 * apprLegal = rawOrder.getBoolean("apprLegal");
	 * apprResearch = rawOrder.getBoolean("apprResearch");
	 * apprPhotoEdit = rawOrder.getBoolean("apprPhotoEdit");
	 * apprFootage = rawOrder.getBoolean("apprFootage");
	 * items = getItems(rawOrder);
	 * destination = GFXSQL.getDestination(rawOrder.getInt("idDestination"));
	 * // notes = rawOrder.getString("notes");
	 * // notes = new NamedList<String>(rawOrder.getString("notes"), NamedList.TYPE.NOTE);
	 * notes = new IndexedSQL<String>(idOrder, rawOrder.getString("notes"));
	 * complete = rawOrder.getBoolean("complete");
	 * closed = rawOrder.getBoolean("closed");
	 * archived = rawOrder.getBoolean("archived");
	 * needsLegal = rawOrder.getBoolean("needsLegal");
	 * needsResearch = rawOrder.getBoolean("needsResearch");
	 * needsPhotoEdit = rawOrder.getBoolean("needsPhotoEdit");
	 * needsFootage = rawOrder.getBoolean("needsFootage");
	 * } catch (SQLException e) {
	 * // TODO Auto-generated catch block
	 * e.printStackTrace();
	 * }
	 * }
	 * public void refreshfromSQL() {
	 * ResultSet rawOrder = GFXSQL.getResultSetFromActiveDB("gfxOrder", "*", this.getIdOrder() + "");
	 * }
	 * public void refreshfromSQL(String fieldName) {
	 * GrfxOrder tempOrder = GFXSQL.getOrder(this.getIdOrder());
	 * Field field;
	 * try {
	 * field = GrfxOrder.class.getDeclaredField(fieldName);
	 * Object value = field.get(tempOrder);
	 * if (fieldName.equals("showName")) {
	 * setShowNameQuiet((ShowName) value);
	 * } else if (fieldName.equals("summary")) {
	 * setSummaryQuiet((IndexedSQL<String>) value);
	 * } else if (fieldName.equals("dueDate")) {
	 * setDueDateQuiet((SQLDate) value);
	 * } else if (fieldName.equals("block")) {
	 * setBlockQuiet((BLOCK) value);
	 * } else if (fieldName.equals("graphicType")) {
	 * setGraphicTypeQuiet((GraphicType) value);
	 * } else if (fieldName.equals("orderedBy")) {
	 * setOrderedByQuiet((User) value);
	 * } else if (fieldName.equals("artist")) {
	 * setArtistQuiet((User) value);
	 * } else if (fieldName.equals("producer")) {
	 * setProducerQuiet((User) value);
	 * } else if (fieldName.equals("researcher")) {
	 * setResearcherQuiet((User) value);
	 * } else if (fieldName.equals("photoEdit")) {
	 * setPhotoEditQuiet((User) value);
	 * } else if (fieldName.equals("footage")) {
	 * setFootageQuiet((User) value);
	 * } else if (fieldName.equals("legal")) {
	 * setLegalQuiet((User) value);
	 * } else if (fieldName.equals("apprResearch")) {
	 * setApprResearchQuiet((Boolean) value);
	 * } else if (fieldName.equals("apprPhotoEdit")) {
	 * setApprPhotoEditQuiet((Boolean) value);
	 * } else if (fieldName.equals("apprFootage")) {
	 * setApprFootageQuiet((Boolean) value);
	 * } else if (fieldName.equals("apprLegal")) {
	 * setApprLegalQuiet((Boolean) value);
	 * } else if (fieldName.equals("items")) {
	 * setItemsQuiet((IndexedSQL<GrfxItemList>) value);
	 * } else if (fieldName.equals("destination")) {
	 * setDestinationQuiet((Destination) value);
	 * } else if (fieldName.equals("notes")) {
	 * setNotesQuiet((IndexedSQL<String>) value);
	 * } else if (fieldName.equals("complete")) {
	 * setCompleteQuiet((Boolean) value);
	 * } else if (fieldName.equals("closed")) {
	 * setClosedQuiet((Boolean) value);
	 * } else if (fieldName.equals("archived")) {
	 * setArchivedQuiet((Boolean) value);
	 * } else if (fieldName.equals("needsResearch")) {
	 * setNeedsResearchQuiet((Boolean) value);
	 * } else if (fieldName.equals("needsPhotoEdit")) {
	 * setNeedsPhotoEditQuiet((Boolean) value);
	 * } else if (fieldName.equals("needsFootage")) {
	 * setNeedsFootageQuiet((Boolean) value);
	 * } else if (fieldName.equals("needsLegal")) {
	 * setNeedsLegalQuiet((Boolean) value);
	 * }
	 * } catch (Exception e) {
	 * e.printStackTrace();
	 * }
	 * }
	 * //
	 * public void addPropertyChangeListener(PropertyChangeListener listener) {
	 * mPcs.addPropertyChangeListener(listener);
	 * }
	 * public void removePropertyChangeListener(PropertyChangeListener listener) {
	 * mPcs.removePropertyChangeListener(listener);
	 * }
	 * @Override
	 * public int hashCode() {
	 * final int prime = 31;
	 * int result = 1;
	 * result = prime * result + (apprFootage ? 1231 : 1237);
	 * result = prime * result + (apprLegal ? 1231 : 1237);
	 * result = prime * result + (apprPhotoEdit ? 1231 : 1237);
	 * result = prime * result + (apprResearch ? 1231 : 1237);
	 * result = prime * result + (archived ? 1231 : 1237);
	 * result = prime * result + ((artist == null) ? 0 : artist.hashCode());
	 * result = prime * result + ((block == null) ? 0 : block.hashCode());
	 * result = prime * result + (closed ? 1231 : 1237);
	 * result = prime * result + (complete ? 1231 : 1237);
	 * result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode());
	 * result = prime * result + ((destination == null) ? 0 : destination.hashCode());
	 * result = prime * result + ((dueDate == null) ? 0 : dueDate.hashCode());
	 * result = prime * result + ((footage == null) ? 0 : footage.hashCode());
	 * result = prime * result + ((graphicType == null) ? 0 : graphicType.hashCode());
	 * result = prime * result + idOrder;
	 * result = prime * result + ((items == null) ? 0 : items.hashCode());
	 * result = prime * result + ((legal == null) ? 0 : legal.hashCode());
	 * result = prime * result + (needsFootage ? 1231 : 1237);
	 * result = prime * result + (needsLegal ? 1231 : 1237);
	 * result = prime * result + (needsPhotoEdit ? 1231 : 1237);
	 * result = prime * result + (needsResearch ? 1231 : 1237);
	 * result = prime * result + ((notes == null) ? 0 : notes.hashCode());
	 * result = prime * result + ((orderedBy == null) ? 0 : orderedBy.hashCode());
	 * result = prime * result + ((photoEdit == null) ? 0 : photoEdit.hashCode());
	 * result = prime * result + ((producer == null) ? 0 : producer.hashCode());
	 * result = prime * result + ((researcher == null) ? 0 : researcher.hashCode());
	 * result = prime * result + ((showName == null) ? 0 : showName.hashCode());
	 * result = prime * result + ((summary == null) ? 0 : summary.hashCode());
	 * return result;
	 * }
	 * @Override
	 * public boolean equals(Object obj) {
	 * if (this == obj)
	 * return true;
	 * if (obj == null)
	 * return false;
	 * if (getClass() != obj.getClass())
	 * return false;
	 * GrfxOrder other = (GrfxOrder) obj;
	 * if (apprFootage != other.apprFootage)
	 * return false;
	 * if (apprLegal != other.apprLegal)
	 * return false;
	 * if (apprPhotoEdit != other.apprPhotoEdit)
	 * return false;
	 * if (apprResearch != other.apprResearch)
	 * return false;
	 * if (archived != other.archived)
	 * return false;
	 * if (artist == null) {
	 * if (other.artist != null)
	 * return false;
	 * } else if (!artist.equals(other.artist))
	 * return false;
	 * if (block != other.block)
	 * return false;
	 * if (closed != other.closed)
	 * return false;
	 * if (complete != other.complete)
	 * return false;
	 * if (creationDate == null) {
	 * if (other.creationDate != null)
	 * return false;
	 * } else if (!creationDate.equals(other.creationDate))
	 * return false;
	 * if (destination == null) {
	 * if (other.destination != null)
	 * return false;
	 * } else if (!destination.equals(other.destination))
	 * return false;
	 * if (dueDate == null) {
	 * if (other.dueDate != null)
	 * return false;
	 * } else if (!dueDate.equals(other.dueDate))
	 * return false;
	 * if (footage == null) {
	 * if (other.footage != null)
	 * return false;
	 * } else if (!footage.equals(other.footage))
	 * return false;
	 * if (graphicType == null) {
	 * if (other.graphicType != null)
	 * return false;
	 * } else if (!graphicType.equals(other.graphicType))
	 * return false;
	 * if (idOrder != other.idOrder)
	 * return false;
	 * if (items == null) {
	 * if (other.items != null)
	 * return false;
	 * } else if (!items.equals(other.items))
	 * return false;
	 * if (legal == null) {
	 * if (other.legal != null)
	 * return false;
	 * } else if (!legal.equals(other.legal))
	 * return false;
	 * if (needsFootage != other.needsFootage)
	 * return false;
	 * if (needsLegal != other.needsLegal)
	 * return false;
	 * if (needsPhotoEdit != other.needsPhotoEdit)
	 * return false;
	 * if (needsResearch != other.needsResearch)
	 * return false;
	 * if (notes == null) {
	 * if (other.notes != null)
	 * return false;
	 * } else if (!notes.equals(other.notes))
	 * return false;
	 * if (orderedBy == null) {
	 * if (other.orderedBy != null)
	 * return false;
	 * } else if (!orderedBy.equals(other.orderedBy))
	 * return false;
	 * if (photoEdit == null) {
	 * if (other.photoEdit != null)
	 * return false;
	 * } else if (!photoEdit.equals(other.photoEdit))
	 * return false;
	 * if (producer == null) {
	 * if (other.producer != null)
	 * return false;
	 * } else if (!producer.equals(other.producer))
	 * return false;
	 * if (researcher == null) {
	 * if (other.researcher != null)
	 * return false;
	 * } else if (!researcher.equals(other.researcher))
	 * return false;
	 * if (showName == null) {
	 * if (other.showName != null)
	 * return false;
	 * } else if (!showName.equals(other.showName))
	 * return false;
	 * if (summary == null) {
	 * if (other.summary != null)
	 * return false;
	 * } else if (!summary.equals(other.summary))
	 * return false;
	 * return true;
	 * }
	 */
}
